var app = getApp();
Page({
  data: {
    invitationCode:'',
    companyName:'',
    userName:'',
    agree: 'agree' ,
    colors:''
  },

  invitationCodeInput(e) {
    this.setData({
      invitationCode: e.detail.value
    })
  },
  companyNameInput(e) {
    this.setData({
      companyName: e.detail.value
    })
  },
  userNameInput(e){
    this.setData({
      userName: e.detail.value
    })
  },
  checkboxChange(e){
    var flag = e.detail.value[0];
    if (flag === undefined) {
      this.data.colors = "#bbb";
      flag = false;
    } else {
      this.data.colors = "#fc6554";
      flag = true;
    }
    this.setData({
      agree: flag,
      colors: this.data.colors
    })
  },
  // bindCompanys(e){
  //   var id = e.currentTarget.dataset.id;
  //   if (this.data.agree === undefined) {
  //     this.data.agree = false;
  //   }
  //   if (this.data.agree == false) {
  //     wx.showModal({
  //       content: '请勾选用户协议',
  //       showCancel: false,
  //     })
  //     return false;
  //   }
  // },
  bindCompany(e){
    if (this.data.userName == '') {
      wx.showModal({
        showCancel: false,
        content: '请输入姓名'
      })
      return false
    }

    // if (this.data.companyName == '') {
    //   wx.showModal({
    //     showCancel: false,
    //     content: '请输入公司名称'
    //   })
    //   return false
    // }
    
    var id = e.currentTarget.dataset.id;
    if (this.data.agree === undefined) {
      this.data.agree = false;
    }
    if (this.data.agree == false) {
      wx.showModal({
        content: '请勾选用户协议',
        showCancel: false,
      })
      return false;
    }

    app.request({
      url: 'api/wechat/bindCompany',
      method: "get",
      data: { company: this.data.companyName, userName: this.data.userName, invitationCode: this.data.invitationCode },
      success: (res) => {
        if (res.data.result) {
          wx.showModal({
            showCancel: false,
            content: '闪销已向您赠送500.00元红包，请到我的钱包查看，提成金额累计达到2000.00元后可申请提现。',
            success: (res) => {
              wx.switchTab({
                url: '/page/LookProduct/index/index',
              })
            },
          })
        } else {
          wx.showModal({
            showCancel: false,
            content: data.errmsg
          })
        }
      }
    })
  },
  
  modalcnt: function () {
    wx.showModal({
      title: '《闪销用户协议》',
      content: '内容',
      success: function (res) {
        if (res.confirm) {
          
        } else if (res.cancel) {
         
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})